
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.io.abinit.abitimer &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.abinit.abitimer</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.abinit.abitimer</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module provides objects for extracting timing data from the ABINIT output files</span>
<span class="sd">It also provides tools to analye and to visualize the parallel efficiency.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">monty.string</span> <span class="kn">import</span> <span class="n">is_string</span><span class="p">,</span> <span class="n">list_strings</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.num</span> <span class="kn">import</span> <span class="n">minloc</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.plotting</span> <span class="kn">import</span> <span class="n">add_fig_kwargs</span><span class="p">,</span> <span class="n">get_ax_fig_plt</span>

<span class="kn">import</span> <span class="nn">logging</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>


<div class="viewcode-block" id="alternate"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.alternate">[docs]</a><span class="k">def</span> <span class="nf">alternate</span><span class="p">(</span><span class="o">*</span><span class="n">iterables</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    [a[0], b[0], ... , a[1], b[1], ..., a[n], b[n] ...]</span>
<span class="sd">    &gt;&gt;&gt; alternate([1,4], [2,5], [3,6])</span>
<span class="sd">    [1, 2, 3, 4, 5, 6]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">items</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">tup</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">iterables</span><span class="p">):</span>
        <span class="n">items</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">item</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">tup</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">items</span></div>


<div class="viewcode-block" id="AbinitTimerParserError"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParserError">[docs]</a><span class="k">class</span> <span class="nc">AbinitTimerParserError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Errors raised by AbinitTimerParser&quot;&quot;&quot;</span></div>


<div class="viewcode-block" id="AbinitTimerParser"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser">[docs]</a><span class="k">class</span> <span class="nc">AbinitTimerParser</span><span class="p">(</span><span class="n">collections</span><span class="o">.</span><span class="n">abc</span><span class="o">.</span><span class="n">Iterable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Responsible for parsing a list of output files, extracting the timing results</span>
<span class="sd">    and analyzing the results.</span>
<span class="sd">    Assume the Abinit output files have been produced with `timopt -1`.</span>

<span class="sd">    Example:</span>

<span class="sd">        parser = AbinitTimerParser()</span>
<span class="sd">        parser.parse(list_of_files)</span>

<span class="sd">    To analyze all *.abo files withing top, use:</span>

<span class="sd">        parser, paths, okfiles = AbinitTimerParser.walk(top=&quot;.&quot;, ext=&quot;.abo&quot;)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># The markers enclosing the data.</span>
    <span class="n">BEGIN_TAG</span> <span class="o">=</span> <span class="s2">&quot;-&lt;BEGIN_TIMER&quot;</span>
    <span class="n">END_TAG</span> <span class="o">=</span> <span class="s2">&quot;-&lt;END_TIMER&gt;&quot;</span>

    <span class="n">Error</span> <span class="o">=</span> <span class="n">AbinitTimerParserError</span>

    <span class="c1"># DEFAULT_MPI_RANK = &quot;0&quot;</span>

<div class="viewcode-block" id="AbinitTimerParser.walk"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.walk">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">walk</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">top</span><span class="o">=</span><span class="s2">&quot;.&quot;</span><span class="p">,</span> <span class="n">ext</span><span class="o">=</span><span class="s2">&quot;.abo&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Scan directory tree starting from top, look for files with extension `ext` and</span>
<span class="sd">        parse timing data.</span>

<span class="sd">        Return: (parser, paths, okfiles)</span>
<span class="sd">            where `parser` is the new object, `paths` is the list of files found and `okfiles`</span>
<span class="sd">            is the list of files that have been parsed successfully.</span>
<span class="sd">            (okfiles == paths) if all files have been parsed.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">paths</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">top</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">f</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="n">ext</span><span class="p">):</span>
                    <span class="n">paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span>

        <span class="n">parser</span> <span class="o">=</span> <span class="bp">cls</span><span class="p">()</span>
        <span class="n">okfiles</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">paths</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">parser</span><span class="p">,</span> <span class="n">paths</span><span class="p">,</span> <span class="n">okfiles</span></div>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize object.&quot;&quot;&quot;</span>
        <span class="c1"># List of files that have been parsed.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_filenames</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># timers[filename][mpi_rank]</span>
        <span class="c1"># contains the timer extracted from the file filename associated to the MPI rank mpi_rank.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_timers</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">OrderedDict</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_timers</span><span class="o">.</span><span class="fm">__iter__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_timers</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">filenames</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;List of files that have been parsed successfully.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_filenames</span>

<div class="viewcode-block" id="AbinitTimerParser.parse"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.parse">[docs]</a>    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filenames</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Read and parse a filename or a list of filenames.</span>
<span class="sd">        Files that cannot be opened are ignored. A single filename may also be given.</span>

<span class="sd">        Return: list of successfully read files.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">filenames</span> <span class="o">=</span> <span class="n">list_strings</span><span class="p">(</span><span class="n">filenames</span><span class="p">)</span>

        <span class="n">read_ok</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">fname</span> <span class="ow">in</span> <span class="n">filenames</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">fh</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">fname</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
                <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;Cannot open file </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">fname</span><span class="p">)</span>
                <span class="k">continue</span>

            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_read</span><span class="p">(</span><span class="n">fh</span><span class="p">,</span> <span class="n">fname</span><span class="p">)</span>
                <span class="n">read_ok</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fname</span><span class="p">)</span>

            <span class="k">except</span> <span class="bp">self</span><span class="o">.</span><span class="n">Error</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;exception while parsing file </span><span class="si">%s</span><span class="s2">:</span><span class="se">\n</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
                <span class="k">continue</span>

            <span class="k">finally</span><span class="p">:</span>
                <span class="n">fh</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="c1"># Add read_ok to the list of files that have been parsed.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_filenames</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">read_ok</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">read_ok</span></div>

    <span class="k">def</span> <span class="nf">_read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fh</span><span class="p">,</span> <span class="n">fname</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Parse the TIMER section&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">fname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_timers</span><span class="p">:</span>
            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">Error</span><span class="p">(</span><span class="s2">&quot;Cannot overwrite timer associated to: </span><span class="si">%s</span><span class="s2"> &quot;</span> <span class="o">%</span> <span class="n">fname</span><span class="p">)</span>

        <span class="k">def</span> <span class="nf">parse_line</span><span class="p">(</span><span class="n">line</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;Parse single line.&quot;&quot;&quot;</span>
            <span class="n">name</span><span class="p">,</span> <span class="n">vals</span> <span class="o">=</span> <span class="n">line</span><span class="p">[:</span><span class="mi">25</span><span class="p">],</span> <span class="n">line</span><span class="p">[</span><span class="mi">25</span><span class="p">:]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">ctime</span><span class="p">,</span> <span class="n">cfract</span><span class="p">,</span> <span class="n">wtime</span><span class="p">,</span> <span class="n">wfract</span><span class="p">,</span> <span class="n">ncalls</span><span class="p">,</span> <span class="n">gflops</span> <span class="o">=</span> <span class="n">vals</span>
            <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                <span class="c1"># v8.3 Added two columns at the end [Speedup, Efficacity]</span>
                <span class="n">ctime</span><span class="p">,</span> <span class="n">cfract</span><span class="p">,</span> <span class="n">wtime</span><span class="p">,</span> <span class="n">wfract</span><span class="p">,</span> <span class="n">ncalls</span><span class="p">,</span> <span class="n">gflops</span><span class="p">,</span> <span class="n">speedup</span><span class="p">,</span> <span class="n">eff</span> <span class="o">=</span> <span class="n">vals</span>

            <span class="k">return</span> <span class="n">AbinitTimerSection</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">ctime</span><span class="p">,</span> <span class="n">cfract</span><span class="p">,</span> <span class="n">wtime</span><span class="p">,</span> <span class="n">wfract</span><span class="p">,</span> <span class="n">ncalls</span><span class="p">,</span> <span class="n">gflops</span><span class="p">)</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">inside</span><span class="p">,</span> <span class="n">has_timer</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="kc">False</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">fh</span><span class="p">:</span>
            <span class="c1"># print(line.strip())</span>
            <span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">BEGIN_TAG</span><span class="p">):</span>
                <span class="n">has_timer</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="n">sections</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">info</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">inside</span> <span class="o">=</span> <span class="mi">1</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">BEGIN_TAG</span><span class="p">):]</span><span class="o">.</span><span class="n">strip</span><span class="p">()[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

                <span class="n">info</span><span class="p">[</span><span class="s2">&quot;fname&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">fname</span>
                <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">):</span>
                    <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">tok</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;=&quot;</span><span class="p">)]</span>
                    <span class="n">info</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>

            <span class="k">elif</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">END_TAG</span><span class="p">):</span>
                <span class="n">inside</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">timer</span> <span class="o">=</span> <span class="n">AbinitTimer</span><span class="p">(</span><span class="n">sections</span><span class="p">,</span> <span class="n">info</span><span class="p">,</span> <span class="n">cpu_time</span><span class="p">,</span> <span class="n">wall_time</span><span class="p">)</span>
                <span class="n">mpi_rank</span> <span class="o">=</span> <span class="n">info</span><span class="p">[</span><span class="s2">&quot;mpi_rank&quot;</span><span class="p">]</span>
                <span class="n">data</span><span class="p">[</span><span class="n">mpi_rank</span><span class="p">]</span> <span class="o">=</span> <span class="n">timer</span>

            <span class="k">elif</span> <span class="n">inside</span><span class="p">:</span>
                <span class="n">inside</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

                <span class="k">if</span> <span class="n">inside</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
                    <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">):</span>
                        <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">tok</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;=&quot;</span><span class="p">)]</span>
                        <span class="n">d</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
                    <span class="n">cpu_time</span><span class="p">,</span> <span class="n">wall_time</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;cpu_time&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;wall_time&quot;</span><span class="p">]</span>

                <span class="k">elif</span> <span class="n">inside</span> <span class="o">&gt;</span> <span class="mi">5</span><span class="p">:</span>
                    <span class="n">sections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">parse_line</span><span class="p">(</span><span class="n">line</span><span class="p">))</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">parse_line</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                    <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                        <span class="n">parser_failed</span> <span class="o">=</span> <span class="kc">True</span>

                    <span class="k">if</span> <span class="ow">not</span> <span class="n">parser_failed</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">Error</span><span class="p">(</span><span class="s2">&quot;line should be empty: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">inside</span><span class="p">)</span> <span class="o">+</span> <span class="n">line</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">has_timer</span><span class="p">:</span>
            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">Error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: No timer section found&quot;</span> <span class="o">%</span> <span class="n">fname</span><span class="p">)</span>

        <span class="c1"># Add it to the dict</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_timers</span><span class="p">[</span><span class="n">fname</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span>

<div class="viewcode-block" id="AbinitTimerParser.timers"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.timers">[docs]</a>    <span class="k">def</span> <span class="nf">timers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mpi_rank</span><span class="o">=</span><span class="s2">&quot;0&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the list of timers associated to the given `filename` and MPI rank mpi_rank.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">filename</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_timers</span><span class="p">[</span><span class="n">filename</span><span class="p">][</span><span class="n">mpi_rank</span><span class="p">]]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_timers</span><span class="p">[</span><span class="n">filename</span><span class="p">][</span><span class="n">mpi_rank</span><span class="p">]</span> <span class="k">for</span> <span class="n">filename</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_filenames</span><span class="p">]</span></div>

<div class="viewcode-block" id="AbinitTimerParser.section_names"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.section_names">[docs]</a>    <span class="k">def</span> <span class="nf">section_names</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ordkey</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the names of sections ordered by ordkey.</span>
<span class="sd">        For the time being, the values are taken from the first timer.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">section_names</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># FIXME this is not trivial</span>
        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">timer</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">timers</span><span class="p">()):</span>
            <span class="k">if</span> <span class="n">idx</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">section_names</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">timer</span><span class="o">.</span><span class="n">order_sections</span><span class="p">(</span><span class="n">ordkey</span><span class="p">)]</span>
                <span class="c1"># check = section_names</span>
                <span class="c1"># else:</span>
                <span class="c1">#  new_set = set( [s.name for s in timer.order_sections(ordkey)])</span>
                <span class="c1">#  section_names.intersection_update(new_set)</span>
                <span class="c1">#  check = check.union(new_set)</span>

        <span class="c1"># if check != section_names:</span>
        <span class="c1">#  print(&quot;sections&quot;, section_names)</span>
        <span class="c1">#  print(&quot;check&quot;,check)</span>

        <span class="k">return</span> <span class="n">section_names</span></div>

<div class="viewcode-block" id="AbinitTimerParser.get_sections"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.get_sections">[docs]</a>    <span class="k">def</span> <span class="nf">get_sections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section_name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the list of sections stored in self.timers() given `section_name`</span>
<span class="sd">        A fake section is returned if the timer does not have section_name.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sections</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">timer</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">timers</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">sect</span> <span class="ow">in</span> <span class="n">timer</span><span class="o">.</span><span class="n">sections</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">sect</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="n">section_name</span><span class="p">:</span>
                    <span class="n">sections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sect</span><span class="p">)</span>
                    <span class="k">break</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">sections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">AbinitTimerSection</span><span class="o">.</span><span class="n">fake</span><span class="p">())</span>

        <span class="k">return</span> <span class="n">sections</span></div>

<div class="viewcode-block" id="AbinitTimerParser.pefficiency"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.pefficiency">[docs]</a>    <span class="k">def</span> <span class="nf">pefficiency</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Analyze the parallel efficiency.</span>

<span class="sd">        Return: :class:`ParallelEfficiency` object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">timers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">timers</span><span class="p">()</span>

        <span class="c1"># Number of CPUs employed in each calculation.</span>
        <span class="n">ncpus</span> <span class="o">=</span> <span class="p">[</span><span class="n">timer</span><span class="o">.</span><span class="n">ncpus</span> <span class="k">for</span> <span class="n">timer</span> <span class="ow">in</span> <span class="n">timers</span><span class="p">]</span>

        <span class="c1"># Find the minimum number of cpus used and its index in timers.</span>
        <span class="n">min_idx</span> <span class="o">=</span> <span class="n">minloc</span><span class="p">(</span><span class="n">ncpus</span><span class="p">)</span>
        <span class="n">min_ncpus</span> <span class="o">=</span> <span class="n">ncpus</span><span class="p">[</span><span class="n">min_idx</span><span class="p">]</span>

        <span class="c1"># Reference timer</span>
        <span class="n">ref_t</span> <span class="o">=</span> <span class="n">timers</span><span class="p">[</span><span class="n">min_idx</span><span class="p">]</span>

        <span class="c1"># Compute the parallel efficiency (total and section efficiency)</span>
        <span class="n">peff</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">ctime_peff</span> <span class="o">=</span> <span class="p">[(</span><span class="n">min_ncpus</span> <span class="o">*</span> <span class="n">ref_t</span><span class="o">.</span><span class="n">wall_time</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">wall_time</span> <span class="o">*</span> <span class="n">ncp</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">ncp</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">timers</span><span class="p">,</span> <span class="n">ncpus</span><span class="p">)]</span>
        <span class="n">wtime_peff</span> <span class="o">=</span> <span class="p">[(</span><span class="n">min_ncpus</span> <span class="o">*</span> <span class="n">ref_t</span><span class="o">.</span><span class="n">cpu_time</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">cpu_time</span> <span class="o">*</span> <span class="n">ncp</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">ncp</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">timers</span><span class="p">,</span> <span class="n">ncpus</span><span class="p">)]</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">timers</span><span class="p">)</span>

        <span class="n">peff</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">peff</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">][</span><span class="s2">&quot;cpu_time&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ctime_peff</span>
        <span class="n">peff</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">][</span><span class="s2">&quot;wall_time&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">wtime_peff</span>
        <span class="n">peff</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">][</span><span class="s2">&quot;cpu_fract&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">n</span> <span class="o">*</span> <span class="p">[</span><span class="mi">100</span><span class="p">]</span>
        <span class="n">peff</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">][</span><span class="s2">&quot;wall_fract&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">n</span> <span class="o">*</span> <span class="p">[</span><span class="mi">100</span><span class="p">]</span>

        <span class="k">for</span> <span class="n">sect_name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">section_names</span><span class="p">():</span>
            <span class="c1"># print(sect_name)</span>
            <span class="n">ref_sect</span> <span class="o">=</span> <span class="n">ref_t</span><span class="o">.</span><span class="n">get_section</span><span class="p">(</span><span class="n">sect_name</span><span class="p">)</span>
            <span class="n">sects</span> <span class="o">=</span> <span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">get_section</span><span class="p">(</span><span class="n">sect_name</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">timers</span><span class="p">]</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">ctime_peff</span> <span class="o">=</span> <span class="p">[(</span><span class="n">min_ncpus</span> <span class="o">*</span> <span class="n">ref_sect</span><span class="o">.</span><span class="n">cpu_time</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">cpu_time</span> <span class="o">*</span> <span class="n">ncp</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">ncp</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">sects</span><span class="p">,</span> <span class="n">ncpus</span><span class="p">)]</span>
                <span class="n">wtime_peff</span> <span class="o">=</span> <span class="p">[(</span><span class="n">min_ncpus</span> <span class="o">*</span> <span class="n">ref_sect</span><span class="o">.</span><span class="n">wall_time</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">wall_time</span> <span class="o">*</span> <span class="n">ncp</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">ncp</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">sects</span><span class="p">,</span> <span class="n">ncpus</span><span class="p">)]</span>
            <span class="k">except</span> <span class="ne">ZeroDivisionError</span><span class="p">:</span>
                <span class="n">ctime_peff</span> <span class="o">=</span> <span class="n">n</span> <span class="o">*</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">wtime_peff</span> <span class="o">=</span> <span class="n">n</span> <span class="o">*</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

            <span class="k">assert</span> <span class="n">sect_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">peff</span>
            <span class="n">peff</span><span class="p">[</span><span class="n">sect_name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">peff</span><span class="p">[</span><span class="n">sect_name</span><span class="p">][</span><span class="s2">&quot;cpu_time&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ctime_peff</span>
            <span class="n">peff</span><span class="p">[</span><span class="n">sect_name</span><span class="p">][</span><span class="s2">&quot;wall_time&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">wtime_peff</span>

            <span class="n">peff</span><span class="p">[</span><span class="n">sect_name</span><span class="p">][</span><span class="s2">&quot;cpu_fract&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">cpu_fract</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">sects</span><span class="p">]</span>
            <span class="n">peff</span><span class="p">[</span><span class="n">sect_name</span><span class="p">][</span><span class="s2">&quot;wall_fract&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">wall_fract</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">sects</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">ParallelEfficiency</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_filenames</span><span class="p">,</span> <span class="n">min_idx</span><span class="p">,</span> <span class="n">peff</span><span class="p">)</span></div>

<div class="viewcode-block" id="AbinitTimerParser.summarize"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.summarize">[docs]</a>    <span class="k">def</span> <span class="nf">summarize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return pandas DataFrame with the most important results stored in the timers.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
        <span class="n">colnames</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;fname&quot;</span><span class="p">,</span> <span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="s2">&quot;cpu_time&quot;</span><span class="p">,</span> <span class="s2">&quot;mpi_nprocs&quot;</span><span class="p">,</span> <span class="s2">&quot;omp_nthreads&quot;</span><span class="p">,</span> <span class="s2">&quot;mpi_rank&quot;</span><span class="p">]</span>

        <span class="n">frame</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">colnames</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">timer</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">timers</span><span class="p">()):</span>
            <span class="n">frame</span> <span class="o">=</span> <span class="n">frame</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">timer</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">colnames</span><span class="p">},</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">frame</span><span class="p">[</span><span class="s2">&quot;tot_ncpus&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">frame</span><span class="p">[</span><span class="s2">&quot;mpi_nprocs&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="n">frame</span><span class="p">[</span><span class="s2">&quot;omp_nthreads&quot;</span><span class="p">]</span>

        <span class="c1"># Compute parallel efficiency (use the run with min number of cpus to normalize).</span>
        <span class="n">i</span> <span class="o">=</span> <span class="n">frame</span><span class="p">[</span><span class="s2">&quot;tot_ncpus&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="o">.</span><span class="n">argmin</span><span class="p">()</span>
        <span class="n">ref_wtime</span> <span class="o">=</span> <span class="n">frame</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="s2">&quot;wall_time&quot;</span><span class="p">]</span>
        <span class="n">ref_ncpus</span> <span class="o">=</span> <span class="n">frame</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="s2">&quot;tot_ncpus&quot;</span><span class="p">]</span>
        <span class="n">frame</span><span class="p">[</span><span class="s2">&quot;peff&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">ref_ncpus</span> <span class="o">*</span> <span class="n">ref_wtime</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">frame</span><span class="p">[</span><span class="s2">&quot;wall_time&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="n">frame</span><span class="p">[</span><span class="s2">&quot;tot_ncpus&quot;</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">frame</span></div>

<div class="viewcode-block" id="AbinitTimerParser.plot_efficiency"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.plot_efficiency">[docs]</a>    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">plot_efficiency</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="n">what</span><span class="o">=</span><span class="s2">&quot;good+bad&quot;</span><span class="p">,</span> <span class="n">nmax</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot the parallel efficiency</span>

<span class="sd">        Args:</span>
<span class="sd">            key: Parallel efficiency is computed using the wall_time.</span>
<span class="sd">            what: Specifies what to plot: `good` for sections with good parallel efficiency.</span>
<span class="sd">                `bad` for sections with bad efficiency. Options can be concatenated with `+`.</span>
<span class="sd">            nmax: Maximum number of entries in plot</span>
<span class="sd">            ax: matplotlib :class:`Axes` or None if a new figure should be created.</span>

<span class="sd">        ================  ====================================================</span>
<span class="sd">        kwargs            Meaning</span>
<span class="sd">        ================  ====================================================</span>
<span class="sd">        linewidth         matplotlib linewidth. Default: 2.0</span>
<span class="sd">        markersize        matplotlib markersize. Default: 10</span>
<span class="sd">        ================  ====================================================</span>

<span class="sd">        Returns:</span>
<span class="sd">            `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ax</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">plt</span> <span class="o">=</span> <span class="n">get_ax_fig_plt</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span>
        <span class="n">lw</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;linewidth&quot;</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">)</span>
        <span class="n">msize</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;markersize&quot;</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;+&quot;</span><span class="p">)</span>

        <span class="n">timers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">timers</span><span class="p">()</span>
        <span class="n">peff</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pefficiency</span><span class="p">()</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">timers</span><span class="p">)</span>
        <span class="n">xx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>

        <span class="c1"># ax.set_color_cycle([&#39;g&#39;, &#39;b&#39;, &#39;c&#39;, &#39;m&#39;, &#39;y&#39;, &#39;k&#39;])</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_prop_cycle</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;m&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="s1">&#39;k&#39;</span><span class="p">])</span>

        <span class="n">lines</span><span class="p">,</span> <span class="n">legend_entries</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[]</span>
        <span class="c1"># Plot sections with good efficiency.</span>
        <span class="k">if</span> <span class="s2">&quot;good&quot;</span> <span class="ow">in</span> <span class="n">what</span><span class="p">:</span>
            <span class="n">good</span> <span class="o">=</span> <span class="n">peff</span><span class="o">.</span><span class="n">good_sections</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">key</span><span class="p">,</span> <span class="n">nmax</span><span class="o">=</span><span class="n">nmax</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">g</span> <span class="ow">in</span> <span class="n">good</span><span class="p">:</span>
                <span class="c1"># print(g, peff[g])</span>
                <span class="n">yy</span> <span class="o">=</span> <span class="n">peff</span><span class="p">[</span><span class="n">g</span><span class="p">][</span><span class="n">key</span><span class="p">]</span>
                <span class="n">line</span><span class="p">,</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">xx</span><span class="p">,</span> <span class="n">yy</span><span class="p">,</span> <span class="s2">&quot;--&gt;&quot;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="n">lw</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="n">msize</span><span class="p">)</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                <span class="n">legend_entries</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">g</span><span class="p">)</span>

        <span class="c1"># Plot sections with bad efficiency.</span>
        <span class="k">if</span> <span class="s2">&quot;bad&quot;</span> <span class="ow">in</span> <span class="n">what</span><span class="p">:</span>
            <span class="n">bad</span> <span class="o">=</span> <span class="n">peff</span><span class="o">.</span><span class="n">bad_sections</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">key</span><span class="p">,</span> <span class="n">nmax</span><span class="o">=</span><span class="n">nmax</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">bad</span><span class="p">:</span>
                <span class="c1"># print(b, peff[b])</span>
                <span class="n">yy</span> <span class="o">=</span> <span class="n">peff</span><span class="p">[</span><span class="n">b</span><span class="p">][</span><span class="n">key</span><span class="p">]</span>
                <span class="n">line</span><span class="p">,</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">xx</span><span class="p">,</span> <span class="n">yy</span><span class="p">,</span> <span class="s2">&quot;-.&lt;&quot;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="n">lw</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="n">msize</span><span class="p">)</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                <span class="n">legend_entries</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>

        <span class="c1"># Add total if not already done</span>
        <span class="k">if</span> <span class="s2">&quot;total&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">legend_entries</span><span class="p">:</span>
            <span class="n">yy</span> <span class="o">=</span> <span class="n">peff</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">][</span><span class="n">key</span><span class="p">]</span>
            <span class="n">total_line</span><span class="p">,</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">xx</span><span class="p">,</span> <span class="n">yy</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="n">lw</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="n">msize</span><span class="p">)</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">total_line</span><span class="p">)</span>
            <span class="n">legend_entries</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;total&quot;</span><span class="p">)</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">lines</span><span class="p">,</span> <span class="n">legend_entries</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="s2">&quot;best&quot;</span><span class="p">,</span> <span class="n">shadow</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># ax.set_title(title)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Total_NCPUs&#39;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Efficiency&#39;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Set xticks and labels.</span>
        <span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;MPI=</span><span class="si">%d</span><span class="s2">, OMP=</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">mpi_nprocs</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">omp_nthreads</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">timers</span><span class="p">]</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">(</span><span class="n">xx</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">(</span><span class="n">labels</span><span class="p">,</span> <span class="n">fontdict</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">minor</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">rotation</span><span class="o">=</span><span class="mi">15</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">fig</span></div>

<div class="viewcode-block" id="AbinitTimerParser.plot_pie"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.plot_pie">[docs]</a>    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">plot_pie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="n">minfract</span><span class="o">=</span><span class="mf">0.05</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot pie charts of the different timers.</span>

<span class="sd">        Args:</span>
<span class="sd">            key: Keyword used to extract data from timers.</span>
<span class="sd">            minfract: Don&#39;t show sections whose relative weight is less that minfract.</span>

<span class="sd">        Returns:</span>
<span class="sd">            `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">timers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">timers</span><span class="p">()</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">timers</span><span class="p">)</span>

        <span class="c1"># Make square figures and axes</span>
        <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
        <span class="kn">from</span> <span class="nn">matplotlib.gridspec</span> <span class="kn">import</span> <span class="n">GridSpec</span>
        <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">gcf</span><span class="p">()</span>
        <span class="n">gspec</span> <span class="o">=</span> <span class="n">GridSpec</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">timer</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">timers</span><span class="p">):</span>
            <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="n">gspec</span><span class="p">[</span><span class="n">idx</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">timer</span><span class="p">))</span>
            <span class="n">timer</span><span class="o">.</span><span class="n">pie</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">key</span><span class="p">,</span> <span class="n">minfract</span><span class="o">=</span><span class="n">minfract</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">fig</span></div>

<div class="viewcode-block" id="AbinitTimerParser.plot_stacked_hist"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.plot_stacked_hist">[docs]</a>    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">plot_stacked_hist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="n">nmax</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot stacked histogram of the different timers.</span>

<span class="sd">        Args:</span>
<span class="sd">            key: Keyword used to extract data from the timers. Only the first `nmax`</span>
<span class="sd">                sections with largest value are show.</span>
<span class="sd">            mmax: Maximum nuber of sections to show. Other entries are grouped together</span>
<span class="sd">                in the `others` section.</span>
<span class="sd">            ax: matplotlib :class:`Axes` or None if a new figure should be created.</span>

<span class="sd">        Returns:</span>
<span class="sd">            `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ax</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">plt</span> <span class="o">=</span> <span class="n">get_ax_fig_plt</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span>

        <span class="n">mpi_rank</span> <span class="o">=</span> <span class="s2">&quot;0&quot;</span>
        <span class="n">timers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">timers</span><span class="p">(</span><span class="n">mpi_rank</span><span class="o">=</span><span class="n">mpi_rank</span><span class="p">)</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">timers</span><span class="p">)</span>

        <span class="n">names</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[]</span>
        <span class="n">rest</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">sname</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">section_names</span><span class="p">(</span><span class="n">ordkey</span><span class="o">=</span><span class="n">key</span><span class="p">)):</span>
            <span class="n">sections</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sections</span><span class="p">(</span><span class="n">sname</span><span class="p">)</span>
            <span class="n">svals</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">sections</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">idx</span> <span class="o">&lt;</span> <span class="n">nmax</span><span class="p">:</span>
                <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sname</span><span class="p">)</span>
                <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">svals</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">rest</span> <span class="o">+=</span> <span class="n">svals</span>

        <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;others (nmax=</span><span class="si">%d</span><span class="s2">)&quot;</span> <span class="o">%</span> <span class="n">nmax</span><span class="p">)</span>
        <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rest</span><span class="p">)</span>

        <span class="c1"># The dataset is stored in values. Now create the stacked histogram.</span>
        <span class="n">ind</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>  <span class="c1"># the locations for the groups</span>
        <span class="n">width</span> <span class="o">=</span> <span class="mf">0.35</span>  <span class="c1"># the width of the bars</span>
        <span class="n">colors</span> <span class="o">=</span> <span class="n">nmax</span> <span class="o">*</span> <span class="p">[</span><span class="s1">&#39;r&#39;</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="s1">&#39;m&#39;</span><span class="p">]</span>

        <span class="n">bars</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">bottom</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">vals</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">values</span><span class="p">):</span>
            <span class="n">color</span> <span class="o">=</span> <span class="n">colors</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span>
            <span class="n">bar</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">vals</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span> <span class="n">bottom</span><span class="o">=</span><span class="n">bottom</span><span class="p">)</span>
            <span class="n">bars</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">bar</span><span class="p">)</span>
            <span class="n">bottom</span> <span class="o">+=</span> <span class="n">vals</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">&quot;Stacked histogram with the </span><span class="si">%d</span><span class="s2"> most important sections&quot;</span> <span class="o">%</span> <span class="n">nmax</span><span class="p">)</span>

        <span class="n">ticks</span> <span class="o">=</span> <span class="n">ind</span> <span class="o">+</span> <span class="n">width</span> <span class="o">/</span> <span class="mf">2.0</span>
        <span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;MPI=</span><span class="si">%d</span><span class="s2">, OMP=</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">mpi_nprocs</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">omp_nthreads</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">timers</span><span class="p">]</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">(</span><span class="n">ticks</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">(</span><span class="n">labels</span><span class="p">,</span> <span class="n">rotation</span><span class="o">=</span><span class="mi">15</span><span class="p">)</span>

        <span class="c1"># Add legend.</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">([</span><span class="n">bar</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">bar</span> <span class="ow">in</span> <span class="n">bars</span><span class="p">],</span> <span class="n">names</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="s2">&quot;best&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">fig</span></div>

<div class="viewcode-block" id="AbinitTimerParser.plot_all"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerParser.plot_all">[docs]</a>    <span class="k">def</span> <span class="nf">plot_all</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Call all plot methods provided by the parser.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">figs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">app</span> <span class="o">=</span> <span class="n">figs</span><span class="o">.</span><span class="n">append</span>
        <span class="n">app</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plot_stacked_hist</span><span class="p">(</span><span class="n">show</span><span class="o">=</span><span class="n">show</span><span class="p">))</span>
        <span class="n">app</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plot_efficiency</span><span class="p">(</span><span class="n">show</span><span class="o">=</span><span class="n">show</span><span class="p">))</span>
        <span class="n">app</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plot_pie</span><span class="p">(</span><span class="n">show</span><span class="o">=</span><span class="n">show</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">figs</span></div></div>


<div class="viewcode-block" id="ParallelEfficiency"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.ParallelEfficiency">[docs]</a><span class="k">class</span> <span class="nc">ParallelEfficiency</span><span class="p">(</span><span class="nb">dict</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Store results concerning the parallel efficiency of the job.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filenames</span><span class="p">,</span> <span class="n">ref_idx</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filennames: List of filenames</span>
<span class="sd">            ref_idx: Index of the Reference time (calculation done with the smallest number of cpus)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filenames</span> <span class="o">=</span> <span class="n">filenames</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ref_idx</span> <span class="o">=</span> <span class="n">ref_idx</span>

    <span class="k">def</span> <span class="nf">_order_by_peff</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">criterion</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">estimator</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;min&quot;</span><span class="p">:</span> <span class="nb">min</span><span class="p">,</span>
            <span class="s2">&quot;max&quot;</span><span class="p">:</span> <span class="nb">max</span><span class="p">,</span>
            <span class="s2">&quot;mean&quot;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">items</span><span class="p">:</span> <span class="nb">sum</span><span class="p">(</span><span class="n">items</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">items</span><span class="p">),</span>
        <span class="p">}[</span><span class="n">criterion</span><span class="p">]</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">sect_name</span><span class="p">,</span> <span class="n">peff</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="c1"># Ignore values where we had a division by zero.</span>
            <span class="k">if</span> <span class="nb">all</span><span class="p">([</span><span class="n">v</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">peff</span><span class="p">[</span><span class="n">key</span><span class="p">]]):</span>
                <span class="n">values</span> <span class="o">=</span> <span class="n">peff</span><span class="p">[</span><span class="n">key</span><span class="p">][:]</span>
                <span class="c1"># print(sect_name, values)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">values</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">ref_value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ref_idx</span><span class="p">)</span>
                    <span class="k">assert</span> <span class="n">ref_value</span> <span class="o">==</span> <span class="mf">1.0</span>

                <span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">sect_name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">estimator</span><span class="p">(</span><span class="n">values</span><span class="p">)))</span>

        <span class="n">data</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">reverse</span><span class="o">=</span><span class="n">reverse</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">tuple</span><span class="p">([</span><span class="n">sect_name</span> <span class="k">for</span> <span class="p">(</span><span class="n">sect_name</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span> <span class="ow">in</span> <span class="n">data</span><span class="p">])</span>

<div class="viewcode-block" id="ParallelEfficiency.totable"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.ParallelEfficiency.totable">[docs]</a>    <span class="k">def</span> <span class="nf">totable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return table (list of lists) with timing results.</span>

<span class="sd">        Args:</span>
<span class="sd">            stop: Include results up to stop. None for all</span>
<span class="sd">            reverse: Put items with highest wall_time in first positions if True.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">osects</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_order_by_peff</span><span class="p">(</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="n">criterion</span><span class="o">=</span><span class="s2">&quot;mean&quot;</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="n">reverse</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">stop</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">osects</span> <span class="o">=</span> <span class="n">osects</span><span class="p">[:</span><span class="n">stop</span><span class="p">]</span>

        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filenames</span><span class="p">)</span>
        <span class="n">table</span> <span class="o">=</span> <span class="p">[[</span><span class="s2">&quot;AbinitTimerSection&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">alternate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filenames</span><span class="p">,</span> <span class="n">n</span> <span class="o">*</span> <span class="p">[</span><span class="s2">&quot;%&quot;</span><span class="p">])]</span>
        <span class="k">for</span> <span class="n">sect_name</span> <span class="ow">in</span> <span class="n">osects</span><span class="p">:</span>
            <span class="n">peff</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="n">sect_name</span><span class="p">][</span><span class="s2">&quot;wall_time&quot;</span><span class="p">]</span>
            <span class="n">fract</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="n">sect_name</span><span class="p">][</span><span class="s2">&quot;wall_fract&quot;</span><span class="p">]</span>
            <span class="n">vals</span> <span class="o">=</span> <span class="n">alternate</span><span class="p">(</span><span class="n">peff</span><span class="p">,</span> <span class="n">fract</span><span class="p">)</span>

            <span class="n">table</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">sect_name</span><span class="p">]</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;</span><span class="si">%.2f</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">val</span> <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">vals</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">table</span></div>

<div class="viewcode-block" id="ParallelEfficiency.good_sections"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.ParallelEfficiency.good_sections">[docs]</a>    <span class="k">def</span> <span class="nf">good_sections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="n">criterion</span><span class="o">=</span><span class="s2">&quot;mean&quot;</span><span class="p">,</span> <span class="n">nmax</span><span class="o">=</span><span class="mi">5</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return first `nmax` sections with best value of key `key` using criterion `criterion`.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">good_sections</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_order_by_peff</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">criterion</span><span class="o">=</span><span class="n">criterion</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">good_sections</span><span class="p">[:</span><span class="n">nmax</span><span class="p">]</span></div>

<div class="viewcode-block" id="ParallelEfficiency.bad_sections"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.ParallelEfficiency.bad_sections">[docs]</a>    <span class="k">def</span> <span class="nf">bad_sections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="n">criterion</span><span class="o">=</span><span class="s2">&quot;mean&quot;</span><span class="p">,</span> <span class="n">nmax</span><span class="o">=</span><span class="mi">5</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return first `nmax` sections with worst value of key `key` using criterion `criterion`.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">bad_sections</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_order_by_peff</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">criterion</span><span class="o">=</span><span class="n">criterion</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">bad_sections</span><span class="p">[:</span><span class="n">nmax</span><span class="p">]</span></div></div>


<div class="viewcode-block" id="AbinitTimerSection"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerSection">[docs]</a><span class="k">class</span> <span class="nc">AbinitTimerSection</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Record with the timing results associated to a section of code.&quot;&quot;&quot;</span>
    <span class="n">STR_FIELDS</span> <span class="o">=</span> <span class="p">[</span>
        <span class="s2">&quot;name&quot;</span>
    <span class="p">]</span>

    <span class="n">NUMERIC_FIELDS</span> <span class="o">=</span> <span class="p">[</span>
        <span class="s2">&quot;wall_time&quot;</span><span class="p">,</span>
        <span class="s2">&quot;wall_fract&quot;</span><span class="p">,</span>
        <span class="s2">&quot;cpu_time&quot;</span><span class="p">,</span>
        <span class="s2">&quot;cpu_fract&quot;</span><span class="p">,</span>
        <span class="s2">&quot;ncalls&quot;</span><span class="p">,</span>
        <span class="s2">&quot;gflops&quot;</span><span class="p">,</span>
    <span class="p">]</span>

    <span class="n">FIELDS</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">STR_FIELDS</span> <span class="o">+</span> <span class="n">NUMERIC_FIELDS</span><span class="p">)</span>

<div class="viewcode-block" id="AbinitTimerSection.fake"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerSection.fake">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">fake</span><span class="p">(</span><span class="bp">cls</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a fake section. Mainly used to fill missing entries if needed.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">AbinitTimerSection</span><span class="p">(</span><span class="s2">&quot;fake&quot;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">cpu_time</span><span class="p">,</span> <span class="n">cpu_fract</span><span class="p">,</span> <span class="n">wall_time</span><span class="p">,</span> <span class="n">wall_fract</span><span class="p">,</span> <span class="n">ncalls</span><span class="p">,</span> <span class="n">gflops</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            name: Name of the sections.</span>
<span class="sd">            cpu_time: CPU time in seconds.</span>
<span class="sd">            cpu_fract: Percentage of CPU time.</span>
<span class="sd">            wall_time: Wall-time in seconds.</span>
<span class="sd">            wall_fract: Percentage of wall-time.</span>
<span class="sd">            ncalls: Number of calls</span>
<span class="sd">            gflops: Gigaflops.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cpu_time</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cpu_time</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cpu_fract</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cpu_fract</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wall_time</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">wall_time</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wall_fract</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">wall_fract</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ncalls</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">ncalls</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gflops</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">gflops</span><span class="p">)</span>

<div class="viewcode-block" id="AbinitTimerSection.to_tuple"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerSection.to_tuple">[docs]</a>    <span class="k">def</span> <span class="nf">to_tuple</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Convert object to tuple.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">tuple</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">at</span><span class="p">]</span> <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">AbinitTimerSection</span><span class="o">.</span><span class="n">FIELDS</span><span class="p">])</span></div>

<div class="viewcode-block" id="AbinitTimerSection.to_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerSection.to_dict">[docs]</a>    <span class="k">def</span> <span class="nf">to_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Convert object to dictionary.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">at</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">at</span><span class="p">]</span> <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">AbinitTimerSection</span><span class="o">.</span><span class="n">FIELDS</span><span class="p">}</span></div>

<div class="viewcode-block" id="AbinitTimerSection.to_csvline"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimerSection.to_csvline">[docs]</a>    <span class="k">def</span> <span class="nf">to_csvline</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">with_header</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a string with data in CSV format. Add header if `with_header`&quot;&quot;&quot;</span>
        <span class="n">string</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>

        <span class="k">if</span> <span class="n">with_header</span><span class="p">:</span>
            <span class="n">string</span> <span class="o">+=</span> <span class="s2">&quot;# &quot;</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">at</span> <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">AbinitTimerSection</span><span class="o">.</span><span class="n">FIELDS</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>

        <span class="n">string</span> <span class="o">+=</span> <span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_tuple</span><span class="p">())</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
        <span class="k">return</span> <span class="n">string</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;String representation.&quot;&quot;&quot;</span>
        <span class="n">string</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">AbinitTimerSection</span><span class="o">.</span><span class="n">FIELDS</span><span class="p">:</span>
            <span class="n">string</span> <span class="o">+=</span> <span class="n">a</span> <span class="o">+</span> <span class="s2">&quot; = &quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">a</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span>
        <span class="k">return</span> <span class="n">string</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span></div>


<div class="viewcode-block" id="AbinitTimer"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer">[docs]</a><span class="k">class</span> <span class="nc">AbinitTimer</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Container class storing the timing results.&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sections</span><span class="p">,</span> <span class="n">info</span><span class="p">,</span> <span class="n">cpu_time</span><span class="p">,</span> <span class="n">wall_time</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            sections: List of sections</span>
<span class="sd">            info: Dictionary with extra info.</span>
<span class="sd">            cpu_time: Cpu-time in seconds.</span>
<span class="sd">            wall_time: Wall-time in seconds.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Store sections and names</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sections</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">sections</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">section_names</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sections</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">info</span> <span class="o">=</span> <span class="n">info</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cpu_time</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cpu_time</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wall_time</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">wall_time</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mpi_nprocs</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">info</span><span class="p">[</span><span class="s2">&quot;mpi_nprocs&quot;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">omp_nthreads</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">info</span><span class="p">[</span><span class="s2">&quot;omp_nthreads&quot;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mpi_rank</span> <span class="o">=</span> <span class="n">info</span><span class="p">[</span><span class="s2">&quot;mpi_rank&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fname</span> <span class="o">=</span> <span class="n">info</span><span class="p">[</span><span class="s2">&quot;fname&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">string</span> <span class="o">=</span> <span class="s2">&quot;file=</span><span class="si">%s</span><span class="s2">, wall_time=</span><span class="si">%.1f</span><span class="s2">, mpi_nprocs=</span><span class="si">%d</span><span class="s2">, omp_nthreads=</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fname</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">wall_time</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mpi_nprocs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">omp_nthreads</span><span class="p">)</span>
        <span class="c1"># string += &quot;, rank = &quot; + self.mpi_rank</span>
        <span class="k">return</span> <span class="n">string</span>

    <span class="k">def</span> <span class="nf">__cmp__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">cmp</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">wall_time</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">wall_time</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ncpus</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Total number of CPUs employed.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">mpi_nprocs</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">omp_nthreads</span>

<div class="viewcode-block" id="AbinitTimer.get_section"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.get_section">[docs]</a>    <span class="k">def</span> <span class="nf">get_section</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section_name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return section associated to `section_name`.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">idx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">section_names</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">section_name</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span>
        <span class="n">sect</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sections</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span>
        <span class="k">assert</span> <span class="n">sect</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="n">section_name</span>
        <span class="k">return</span> <span class="n">sect</span></div>

<div class="viewcode-block" id="AbinitTimer.to_csv"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.to_csv">[docs]</a>    <span class="k">def</span> <span class="nf">to_csv</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fileobj</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Write data on file fileobj using CSV format.&quot;&quot;&quot;</span>
        <span class="n">openclose</span> <span class="o">=</span> <span class="n">is_string</span><span class="p">(</span><span class="n">fileobj</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">openclose</span><span class="p">:</span>
            <span class="n">fileobj</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileobj</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">section</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sections</span><span class="p">):</span>
            <span class="n">fileobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">to_csvline</span><span class="p">(</span><span class="n">with_header</span><span class="o">=</span><span class="p">(</span><span class="n">idx</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)))</span>
        <span class="n">fileobj</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">openclose</span><span class="p">:</span>
            <span class="n">fileobj</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

<div class="viewcode-block" id="AbinitTimer.to_table"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.to_table">[docs]</a>    <span class="k">def</span> <span class="nf">to_table</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sort_key</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a table (list of lists) with timer data&quot;&quot;&quot;</span>
        <span class="n">table</span> <span class="o">=</span> <span class="p">[</span><span class="nb">list</span><span class="p">(</span><span class="n">AbinitTimerSection</span><span class="o">.</span><span class="n">FIELDS</span><span class="p">),</span> <span class="p">]</span>
        <span class="n">ord_sections</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">order_sections</span><span class="p">(</span><span class="n">sort_key</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">stop</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">ord_sections</span> <span class="o">=</span> <span class="n">ord_sections</span><span class="p">[:</span><span class="n">stop</span><span class="p">]</span>

        <span class="k">for</span> <span class="n">osect</span> <span class="ow">in</span> <span class="n">ord_sections</span><span class="p">:</span>
            <span class="n">row</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">osect</span><span class="o">.</span><span class="n">to_tuple</span><span class="p">()]</span>
            <span class="n">table</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">row</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">table</span></div>

    <span class="c1"># Maintain old API</span>
    <span class="n">totable</span> <span class="o">=</span> <span class="n">to_table</span>

<div class="viewcode-block" id="AbinitTimer.get_dataframe"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.get_dataframe">[docs]</a>    <span class="k">def</span> <span class="nf">get_dataframe</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sort_key</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return a pandas DataFrame with entries sorted according to `sort_key`.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
        <span class="n">frame</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">AbinitTimerSection</span><span class="o">.</span><span class="n">FIELDS</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">osect</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">order_sections</span><span class="p">(</span><span class="n">sort_key</span><span class="p">):</span>
            <span class="n">frame</span> <span class="o">=</span> <span class="n">frame</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">osect</span><span class="o">.</span><span class="n">to_dict</span><span class="p">(),</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Monkey patch</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">info</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">cpu_time</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cpu_time</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">wall_time</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">wall_time</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">mpi_nprocs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mpi_nprocs</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">omp_nthreads</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">omp_nthreads</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">mpi_rank</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mpi_rank</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">fname</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fname</span>

        <span class="k">return</span> <span class="n">frame</span></div>

<div class="viewcode-block" id="AbinitTimer.get_values"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.get_values">[docs]</a>    <span class="k">def</span> <span class="nf">get_values</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keys</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return a list of values associated to a particular list of keys.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">is_string</span><span class="p">(</span><span class="n">keys</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">keys</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sections</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">values</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span>
                <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sections</span><span class="p">])</span>
            <span class="k">return</span> <span class="n">values</span></div>

<div class="viewcode-block" id="AbinitTimer.names_and_values"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.names_and_values">[docs]</a>    <span class="k">def</span> <span class="nf">names_and_values</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">minval</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">minfract</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="nb">sorted</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Select the entries whose value[key] is &gt;= minval or whose fraction[key] is &gt;= minfract</span>
<span class="sd">        Return the names of the sections and the corresponding values.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">values</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
        <span class="n">names</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span>

        <span class="n">new_names</span><span class="p">,</span> <span class="n">new_values</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[]</span>
        <span class="n">other_val</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="k">if</span> <span class="n">minval</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">minfract</span> <span class="ow">is</span> <span class="kc">None</span>

            <span class="k">for</span> <span class="n">n</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">names</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">v</span> <span class="o">&gt;=</span> <span class="n">minval</span><span class="p">:</span>
                    <span class="n">new_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
                    <span class="n">new_values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">other_val</span> <span class="o">+=</span> <span class="n">v</span>

            <span class="n">new_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;below minval &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">minval</span><span class="p">))</span>
            <span class="n">new_values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">other_val</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">minfract</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">minval</span> <span class="ow">is</span> <span class="kc">None</span>

            <span class="n">total</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sum_sections</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">n</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">names</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">v</span> <span class="o">/</span> <span class="n">total</span> <span class="o">&gt;=</span> <span class="n">minfract</span><span class="p">:</span>
                    <span class="n">new_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
                    <span class="n">new_values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">other_val</span> <span class="o">+=</span> <span class="n">v</span>

            <span class="n">new_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;below minfract &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">minfract</span><span class="p">))</span>
            <span class="n">new_values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">other_val</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># all values</span>
            <span class="n">new_names</span><span class="p">,</span> <span class="n">new_values</span> <span class="o">=</span> <span class="n">names</span><span class="p">,</span> <span class="n">values</span>

        <span class="k">if</span> <span class="nb">sorted</span><span class="p">:</span>
            <span class="c1"># Sort new_values and rearrange new_names.</span>
            <span class="n">nandv</span> <span class="o">=</span> <span class="p">[</span><span class="n">nv</span> <span class="k">for</span> <span class="n">nv</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">new_names</span><span class="p">,</span> <span class="n">new_values</span><span class="p">)]</span>
            <span class="n">nandv</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">new_names</span><span class="p">,</span> <span class="n">new_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">n</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">nandv</span><span class="p">],</span> <span class="p">[</span><span class="n">n</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">nandv</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">new_names</span><span class="p">,</span> <span class="n">new_values</span></div>

    <span class="k">def</span> <span class="nf">_reduce_sections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">operator</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">operator</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="n">keys</span><span class="p">))</span>

<div class="viewcode-block" id="AbinitTimer.sum_sections"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.sum_sections">[docs]</a>    <span class="k">def</span> <span class="nf">sum_sections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keys</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Sum value of keys.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_reduce_sections</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="nb">sum</span><span class="p">)</span></div>

<div class="viewcode-block" id="AbinitTimer.order_sections"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.order_sections">[docs]</a>    <span class="k">def</span> <span class="nf">order_sections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Sort sections according to the value of key.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sections</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="n">s</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">key</span><span class="p">],</span> <span class="n">reverse</span><span class="o">=</span><span class="n">reverse</span><span class="p">)</span></div>

<div class="viewcode-block" id="AbinitTimer.cpuwall_histogram"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.cpuwall_histogram">[docs]</a>    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">cpuwall_histogram</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot histogram with cpu- and wall-time on axis `ax`.</span>

<span class="sd">        Args:</span>
<span class="sd">            ax: matplotlib :class:`Axes` or None if a new figure should be created.</span>

<span class="sd">        Returns: `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ax</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">plt</span> <span class="o">=</span> <span class="n">get_ax_fig_plt</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span>

        <span class="n">nk</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sections</span><span class="p">)</span>
        <span class="n">ind</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">nk</span><span class="p">)</span>  <span class="c1"># the x locations for the groups</span>
        <span class="n">width</span> <span class="o">=</span> <span class="mf">0.35</span>  <span class="c1"># the width of the bars</span>

        <span class="n">cpu_times</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="s2">&quot;cpu_time&quot;</span><span class="p">)</span>
        <span class="n">rects1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">cpu_times</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;r&#39;</span><span class="p">)</span>

        <span class="n">wall_times</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="s2">&quot;wall_time&quot;</span><span class="p">)</span>
        <span class="n">rects2</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">ind</span> <span class="o">+</span> <span class="n">width</span><span class="p">,</span> <span class="n">wall_times</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;y&#39;</span><span class="p">)</span>

        <span class="c1"># Add ylable and title</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Time (s)&#39;</span><span class="p">)</span>

        <span class="c1"># plt.title(&#39;CPU-time and Wall-time for the different sections of the code&#39;)</span>

        <span class="n">ticks</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">(</span><span class="n">ind</span> <span class="o">+</span> <span class="n">width</span><span class="p">,</span> <span class="n">ticks</span><span class="p">)</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">((</span><span class="n">rects1</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">rects2</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="p">(</span><span class="s1">&#39;CPU&#39;</span><span class="p">,</span> <span class="s1">&#39;Wall&#39;</span><span class="p">),</span> <span class="n">loc</span><span class="o">=</span><span class="s2">&quot;best&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">fig</span></div>

<div class="viewcode-block" id="AbinitTimer.pie"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.pie">[docs]</a>    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">pie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">&quot;wall_time&quot;</span><span class="p">,</span> <span class="n">minfract</span><span class="o">=</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot pie chart for this timer.</span>

<span class="sd">        Args:</span>
<span class="sd">            key: Keyword used to extract data from the timer.</span>
<span class="sd">            minfract: Don&#39;t show sections whose relative weight is less that minfract.</span>
<span class="sd">            ax: matplotlib :class:`Axes` or None if a new figure should be created.</span>

<span class="sd">        Returns: `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ax</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">plt</span> <span class="o">=</span> <span class="n">get_ax_fig_plt</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span>
        <span class="c1"># Set aspect ratio to be equal so that pie is drawn as a circle.</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">axis</span><span class="p">(</span><span class="s2">&quot;equal&quot;</span><span class="p">)</span>
        <span class="c1"># Don&#39;t show section whose value is less that minfract</span>
        <span class="n">labels</span><span class="p">,</span> <span class="n">vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">names_and_values</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">minfract</span><span class="o">=</span><span class="n">minfract</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">pie</span><span class="p">(</span><span class="n">vals</span><span class="p">,</span> <span class="n">explode</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">labels</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span> <span class="n">autopct</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">%1.1f%%</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">shadow</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">fig</span></div>

<div class="viewcode-block" id="AbinitTimer.scatter_hist"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abitimer.html#pymatgen.io.abinit.abitimer.AbinitTimer.scatter_hist">[docs]</a>    <span class="nd">@add_fig_kwargs</span>
    <span class="k">def</span> <span class="nf">scatter_hist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Scatter plot + histogram.</span>

<span class="sd">        Args:</span>
<span class="sd">            ax: matplotlib :class:`Axes` or None if a new figure should be created.</span>

<span class="sd">        Returns: `matplotlib` figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">mpl_toolkits.axes_grid1</span> <span class="kn">import</span> <span class="n">make_axes_locatable</span>
        <span class="n">ax</span><span class="p">,</span> <span class="n">fig</span><span class="p">,</span> <span class="n">plt</span> <span class="o">=</span> <span class="n">get_ax_fig_plt</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span>

        <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="s2">&quot;cpu_time&quot;</span><span class="p">))</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="s2">&quot;wall_time&quot;</span><span class="p">))</span>

        <span class="c1"># the scatter plot:</span>
        <span class="n">axScatter</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">axScatter</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
        <span class="n">axScatter</span><span class="o">.</span><span class="n">set_aspect</span><span class="p">(</span><span class="s2">&quot;auto&quot;</span><span class="p">)</span>

        <span class="c1"># create new axes on the right and on the top of the current axes</span>
        <span class="c1"># The first argument of the new_vertical(new_horizontal) method is</span>
        <span class="c1"># the height (width) of the axes to be created in inches.</span>
        <span class="n">divider</span> <span class="o">=</span> <span class="n">make_axes_locatable</span><span class="p">(</span><span class="n">axScatter</span><span class="p">)</span>
        <span class="n">axHistx</span> <span class="o">=</span> <span class="n">divider</span><span class="o">.</span><span class="n">append_axes</span><span class="p">(</span><span class="s2">&quot;top&quot;</span><span class="p">,</span> <span class="mf">1.2</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">sharex</span><span class="o">=</span><span class="n">axScatter</span><span class="p">)</span>
        <span class="n">axHisty</span> <span class="o">=</span> <span class="n">divider</span><span class="o">.</span><span class="n">append_axes</span><span class="p">(</span><span class="s2">&quot;right&quot;</span><span class="p">,</span> <span class="mf">1.2</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">sharey</span><span class="o">=</span><span class="n">axScatter</span><span class="p">)</span>

        <span class="c1"># make some labels invisible</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">axHistx</span><span class="o">.</span><span class="n">get_xticklabels</span><span class="p">()</span> <span class="o">+</span> <span class="n">axHisty</span><span class="o">.</span><span class="n">get_yticklabels</span><span class="p">(),</span> <span class="n">visible</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

        <span class="c1"># now determine nice limits by hand:</span>
        <span class="n">binwidth</span> <span class="o">=</span> <span class="mf">0.25</span>
        <span class="n">xymax</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="n">x</span><span class="p">)),</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="n">y</span><span class="p">))])</span>
        <span class="n">lim</span> <span class="o">=</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">xymax</span> <span class="o">/</span> <span class="n">binwidth</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">binwidth</span>

        <span class="n">bins</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="n">lim</span><span class="p">,</span> <span class="n">lim</span> <span class="o">+</span> <span class="n">binwidth</span><span class="p">,</span> <span class="n">binwidth</span><span class="p">)</span>
        <span class="n">axHistx</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">bins</span><span class="o">=</span><span class="n">bins</span><span class="p">)</span>
        <span class="n">axHisty</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">bins</span><span class="o">=</span><span class="n">bins</span><span class="p">,</span> <span class="n">orientation</span><span class="o">=</span><span class="s1">&#39;horizontal&#39;</span><span class="p">)</span>

        <span class="c1"># the xaxis of axHistx and yaxis of axHisty are shared with axScatter,</span>
        <span class="c1"># thus there is no need to manually adjust the xlim and ylim of these axis.</span>

        <span class="c1"># axHistx.axis[&quot;bottom&quot;].major_ticklabels.set_visible(False)</span>
        <span class="k">for</span> <span class="n">tl</span> <span class="ow">in</span> <span class="n">axHistx</span><span class="o">.</span><span class="n">get_xticklabels</span><span class="p">():</span>
            <span class="n">tl</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
            <span class="n">axHistx</span><span class="o">.</span><span class="n">set_yticks</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">100</span><span class="p">])</span>

            <span class="c1"># axHisty.axis[&quot;left&quot;].major_ticklabels.set_visible(False)</span>
            <span class="k">for</span> <span class="n">tl</span> <span class="ow">in</span> <span class="n">axHisty</span><span class="o">.</span><span class="n">get_yticklabels</span><span class="p">():</span>
                <span class="n">tl</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
                <span class="n">axHisty</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">100</span><span class="p">])</span>

        <span class="c1"># plt.draw()</span>
        <span class="k">return</span> <span class="n">fig</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.abinit.abitimer</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>